package com.travel.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.aspect.Log;
import com.travel.entity.Browse;
import com.travel.entity.Report;
import com.travel.service.BrowseService;

@Controller
@RequestMapping("/Browse")
public class BrowseController {

	@Autowired
	BrowseService browseService;
	
	@Log("进入流量统计管理")
	@RequiresPermissions("Browse")
    @RequestMapping("/golist.do")
    public String tolist() {
        return "module/Browse/list";
    }
	
	@Log("查询流量统计列表")
	@RequiresPermissions("BrowseList")
    @RequestMapping(value = "/list.do", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> list(ServletRequest request, ServletResponse response, Page<Browse> page, Browse view) {
        Map<String, Object> map = new HashMap<>();
        page.setDescs("id");
        List<Browse> list = browseService.getBrowse(page, view);
        map.put("records", list);
        map.put("total", page.getTotal());
        return map;
    }
	
	@Log("获取流量统计")
	@RequiresPermissions("EditBrowse")
    @RequestMapping("/goEdit.do")
    public ModelAndView goEdit(Browse entity) {
        Map<String, Object> map = new HashMap<>();
        if (entity.getId() != null) {
            entity = this.browseService.selectById(entity.getId());
        }
        map.put("entity", entity);
        return new ModelAndView("module/Browse/edit", map);
    }
	
	@Log("进入流量报表")
	@RequiresPermissions("BrowseReport")
    @RequestMapping("/goReport.do")
    public String toReport() {
        return "module/Browse/report";
    }
	
	
	/**
	 * 根据日期查询
	 * @param time
	 * @return
	 */
	@Log("根据日期查询报表")
	@RequestMapping(value="/flowday.do",method=RequestMethod.POST)
	@ResponseBody
	public List<Report> flowday(String time){
		List<Report> today=browseService.queryFlowDay(time);
		return today;
	}
	
	/**
	 * 查询今天
	 * @return
	 */
	@Log("获取今天web端报表")
	@RequestMapping(value="/today.do",method=RequestMethod.POST)
	@ResponseBody
	public List<Report> today(){
		List<Report> today=browseService.queryToday();
		return today;
	}
	
	/**
	 * 查询昨天
	 * @return
	 */
	@Log("获取昨天web端报表")
	@RequestMapping(value="/yesterday.do",method=RequestMethod.POST)
	@ResponseBody
	public List<Report> yesterday(){
		List<Report> yesterday=browseService.queryYesterday();
		return yesterday;
	}
	
	
	
}
